from transformers import BertTokenizer, BertModel
import torch
from bert_score import score

def bert_score_evaluation(generated_summary, reference_summary):
    model_path ='bert-base-chinese'
    # 加载分词器
    tokenizer = BertTokenizer.from_pretrained(model_path)
    # 加载模型
    model =BertModel.from_pretrained(model_path)
    rec = [generated_summary] * len(reference_summary)
    P, R, F1 = score(rec, reference_summary, lang="chinese",model_type=model_path)
    return {
        "precision": P.mean().item(),
        "recall": R.mean().item(),
        "f1": F1.mean().item()
    }